package com.zhuss.core.processor;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.common.ListVo;
import com.zhuss.common.SelectVo;
import com.zhuss.enums.ConfigTypeEnum;
import com.zhuss.util.DateUtil;

@Component("enumConfig")
@SuppressWarnings("unchecked")
public class EnumConfig {
	
	@Autowired
	@Qualifier("configRead")
	private ConfigRead configRead;
    
	
	public List<String> getKeyWord(String type) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(type);
		List<String> keyWordList = new ArrayList<String>();
		for (ListVo l : configList) {
			keyWordList.add('%' + l.getLabel() + '%');
		}
		return keyWordList;
	}
	
	
	
	public Date getTime(String type) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(type);
		String value = "";
		for (ListVo l : configList) {
			value = l.getLabel();
			break;
		}
		return "".equals(value) ? new Date() : DateUtil.toDateByTimeMinute(value);
	}
	
	
	
	public List<SelectVo> list(String type) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(type);
		List<SelectVo> selectVoList = new ArrayList<SelectVo>();
		for (ListVo l : configList) {
			selectVoList.add(new SelectVo(l.getKey().intValue(), l.getLabel(), l.getLabel()));
		}
		return selectVoList;
	}

	
	public List<SelectVo> listSelectFoodCategory() {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.餐品类型.tag());
		List<SelectVo> selectVoList = new ArrayList<SelectVo>();
		for (ListVo l : configList) {
			selectVoList.add(new SelectVo(l.getKey().intValue(), l.getLabel(), l.getTag()));
		}
		return selectVoList;
	}
	
	//维修物料-字典
	public List<SelectVo> listRepairFoodsCategory() {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.维修物料.tag());
		List<SelectVo> selectVoList = new ArrayList<SelectVo>();
		for (ListVo l : configList) {
			selectVoList.add(new SelectVo(l.getKey().intValue(), l.getLabel(), l.getLabel()));
		}
		return selectVoList;
	}

	public List<SelectVo> listSelectTakeoutStartTime() {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.外卖开抢时间.tag());
		List<SelectVo> selectVoList = new ArrayList<SelectVo>();
		for (ListVo l : configList) {
			selectVoList.add(new SelectVo(l.getKey().intValue(), l.getLabel(), l.getLabel()));
		}
		return selectVoList;
	}
	
	public List<SelectVo> listSelectTakeoutFetchTime() {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.外卖取餐时间.tag());
		List<SelectVo> selectVoList = new ArrayList<SelectVo>();
		for (ListVo l : configList) {
			selectVoList.add(new SelectVo(l.getKey().intValue(), l.getLabel(), l.getLabel()));
		}
		return selectVoList;
	}
	
	public String enumName(String type, Integer key) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(type);
		for (ListVo l : configList) {
			if (l.getKey().equals(key)) {
				return l.getLabel();
			}
		}
		return null;
	}

	public String categoryName(Integer category) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.餐品类型.tag());
		for (ListVo l : configList) {
			if (Integer.valueOf(l.getKey() + "").equals(category)) {
				return l.getLabel();
			}
		}
		return null;
	}

	public String investGroupName(Integer investGroup) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.问卷类型.tag());
		for (ListVo l : configList) {
			if (Integer.valueOf(l.getKey() + "").equals(investGroup)) {
				return l.getLabel();
			}
		}
		return null;
	}
	
	public String deviceKindName(Integer type) {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.设备种类.tag());
		for (ListVo l : configList) {
			if (Integer.valueOf(l.getKey() + "").equals(type)) {
				return l.getLabel();
			}
		}
		return null;
	}
	
	public List<SelectVo> listSelectDeviceKind() {
		List<ListVo> configList = (List<ListVo>) configRead.listConfig(ConfigTypeEnum.设备种类.tag());
		List<SelectVo> selectVoList = new ArrayList<SelectVo>();
		for (ListVo l : configList) {
			selectVoList.add(new SelectVo(l.getKey().intValue(), l.getLabel(), l.getTag()));
		}
		return selectVoList;
	}

}
